# 第一阶段：构建依赖
FROM python:3.12-slim as builder

# 配置清华源
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free" > /etc/apt/sources.list && \
    echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free" >> /etc/apt/sources.list

# 安装系统依赖
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    libmariadb-dev \
    default-libmysqlclient-dev \
    zlib1g-dev \
    gcc \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app
COPY requirements.txt .

# 安装 Python 依赖
RUN python -m pip install --upgrade pip && \
    pip install --no-cache-dir \
    -r requirements.txt \
    --global-option=build_ext \
    --global-option="-I/usr/include/mariadb" \
    -i https://pypi.tuna.tsinghua.edu.cn/simple

